﻿using System;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Workbench.Core;
using SharedGenomics.Workbench.Tests.TestObjects;

namespace SharedGenomics.Workbench.Tests.Core
{
    [TestClass]
    public class BuildUpPresenterInitialistionStageTests
    {
        private IUnityContainer container;
        private PresenterInitialisationContext context;
        private BuildUpPresenterInitialisationStage stage;

        [TestInitialize]
        public void Setup()
        {
            this.container = new UnityContainer();
            this.container.RegisterType<IEventBroker, EventBroker>();
            this.container.RegisterType<StubPresenter>();

            this.context = new PresenterInitialisationContext();
            this.context.Container = container;

            this.stage = new BuildUpPresenterInitialisationStage();
        }

        [TestMethod]
        public void ShouldBuildUpPresenter()
        {
            this.context.PresenterType = typeof(StubPresenter);
            this.context.Current = new StubPresenter();

            this.stage.Initialise(context);
            Assert.IsInstanceOfType(context.Current, typeof(StubPresenter));
            StubPresenter presenter = (StubPresenter)context.Current;
            Assert.IsNotNull(presenter.EventBroker);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ShouldThrowIfContextNull()
        {
            this.stage.Initialise(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ShouldThrowIfContainerNull()
        {
            this.context.Container = null;
            this.stage.Initialise(context);
        }
    }
}
